	
/*
*		端口层，抽象端口
*/

#pragma once


#include <boost/asio.hpp>
#include "CxPort.h"
#include <boost/thread.hpp>

namespace ImitateTansfer
{

    using namespace boost::asio::ip;
using boost::asio::ip::tcp;

	class	CxTcpPort	:	public	CxPort
	{
	public:
		CxTcpPort(tcp::socket *sock,UINT	portno=0);
		CxTcpPort();
		~CxTcpPort();

	public:
	
		bool	OpenPort(LPCSTR		portname);
		bool	ClosePort();
		bool	IsOpen()const;
		UINT	GetStatus()const;



		size_t	ReadPort(BYTE *,size_t);	
		size_t	ReadPort(BYTE *,size_t ,
			const boost::function<void (const boost::system::error_code& error ,size_t bytes_transferred) > &);
		size_t	WritePort(BYTE *,size_t );
		size_t  WritePort(CxPackage *);

	private:
		
        static  void		CallBackHandler_Pack(  const boost::system::error_code &,
                                                            size_t ,
                                                            tcp::socket *,
                                                            CxPackage *,
                                                            CxPort	*
															);


	private:
		tcp::socket				*m_psocket;
		UINT					m_portno;
	};


}
